//
//  HomeVC.m
//  MyStock
//
//  Created by 刘翔 on 2024/8/14.
//

#import "HomeVC.h"
#import "HomeSubVC.h"
#import "HomeOneVC.h"



@interface HomeVC ()<JXCategoryViewDelegate,JXCategoryListContainerViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *categoryView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) NSMutableArray *listVCArray;
@property (nonatomic, strong) JXCategoryListContainerView *listVCContainerView;
@property (nonatomic, strong) NSArray *titles;


@end

@implementation HomeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.customNavBar.title = @"热点概念";
    
    WeatherLabel *label = [[WeatherLabel alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    label.attributedText = [[NSAttributedString alloc] initWithString:[AppService shareInstance].weather];
    [self.customNavBar addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.customNavBar).offset(-10);
            make.right.equalTo(self.customNavBar).offset(-20);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(70);
    }];
    
    
    
    self.titles = @[@"开盘啦",@"屠龙刀"];
    self.categoryView = [[JXCategoryTitleView alloc] init];
    self.categoryView.frame = CGRectMake(0, Height_NavBar, kScreenWidth,44);
    self.categoryView.delegate = self;
    self.categoryView.titles = self.titles;
    self.categoryView.titleColor = [UIColor colorWithHexString:@"#333333"];
    self.categoryView.titleSelectedColor = [UIColor colorWithHexString:@"#FB78A3"];
    self.categoryView.titleFont = [UIFont systemFontOfSize:14];
    self.categoryView.backgroundColor = [UIColor colorWithHexString:@"#FFFFFF"];
    self.categoryView.defaultSelectedIndex = 0;
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.lineStyle = JXCategoryIndicatorLineStyle_Normal;
    lineView.lineScrollOffsetX = 5;
    lineView.indicatorColor = [UIColor colorWithHexString:@"#FB78A3"];
    self.categoryView.indicators = @[lineView];
    [self.view addSubview:self.categoryView];
    
    self.listVCContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    self.listVCContainerView.frame = CGRectMake(0, Height_NavBar + 44, kScreenWidth, kScreenHeight - Height_NavBar - Height_TabBar - 44);
    self.listVCContainerView.defaultSelectedIndex = 0;
    [self.view addSubview:self.listVCContainerView];
    
    self.categoryView.contentScrollView = self.listVCContainerView.scrollView;
  

}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index
{
    
    [self.listVCContainerView didClickSelectedItemAtIndex:index];
        
}

//- (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
//    [self.listVCContainerView didClickSelectedItemAtIndex:index];
//}
//
//- (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
//
//
//    [self.listVCContainerView scrollingFromLeftIndex:leftIndex toRightIndex:rightIndex ratio:ratio selectedIndex:categoryView.selectedIndex];
//}

#pragma mark - JXCategoryListContainerViewDelegate

- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    if (index == 0) {
        HomeSubVC *vc = [[HomeSubVC alloc] init];
        return vc;
    }else{
        
        HomeOneVC *vc = [[HomeOneVC alloc] init];
        return vc;
        
    }
    
}

- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}

@end
